/////////////////////////////////////////////////////////////////////
//
//  MOE Framework (Meta Object Encapsulation Framework)
//
//  Original Author: Wiksy Wang, 2011
//
/////////////////////////////////////////////////////////////////////

#ifndef MOE_DATA_MEMBER_META_H
#define MOE_DATA_MEMBER_META_H

#include <boost/function.hpp>

#include "CommonDef.h"
#include "FunctionTypeDef.h"

namespace MOE
{

class DataMemberMeta
{
public:
	explicit DataMemberMeta(const ClassIDType type = InvalidClassID, const DerivedTypes derivedType = DT_Value);

	DataMemberMeta& DefineSetter(const SetterMetaFuncType& setter)
	{
		_setter = setter;
		return *this;
	}

	DataMemberMeta& DefineGetter(const GetterMetaFuncType& getter)
	{
		_getter = getter;
		return *this;
	}

	DataMemberMeta& DefineDirectAccessor(const DirectAccessMetaFuncType& directAccess)
	{
		_directAccess = directAccess;
		return *this;
	}

	ClassIDType GetTypeID() const { return _memberTypeID; }
	DerivedTypes GetDerivedType() const { return _memberDerivedType; }

	bool IsValid() const { return _memberTypeID != InvalidClassID; }

	bool HasSetter() const { return !_setter.empty(); }
	bool HasGetter() const { return !_getter.empty(); }
	bool HasDirectAccess() const { return !_directAccess.empty(); }

	void Set(Address object, ConstAddress data) const
	{
		_setter(object, data);
	}

	void Get(Address object, Address data) const
	{
		_getter(object, data);
	}

	Address DirectAccess(Address object) const
	{
		return _directAccess(object);
	}

	static const DataMemberMeta InvalidMember;

private:
	ClassIDType _memberTypeID;
	DerivedTypes _memberDerivedType;
	SetterMetaFuncType _setter;
	GetterMetaFuncType _getter;
	DirectAccessMetaFuncType _directAccess;
};

}

#endif
